import type { Ref } from "vue";
import instance from "../request";

/* 
 /returnApply/list  分页查询退货申请
*/

interface IReturnApplyListParmas {
  IReturnApplyListParmas: string;
  handleMan: string;
  handleTime: string;
  pageNum: string;
  id: number;
  pageSize: number;
  receiverKeyword: string;
  status: 0 | 1 | 2 | 3;
}
interface IReturnApplyListRes {
  list: IIReturnApplyListItem[];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}

interface IIReturnApplyListItem {
  companyAddressId: number;
  createTime: string;
  description: string;
  handleMan: string;
  handleNote: string;
  handleTime: string;
  id: number;
  memberUsername: string;
  orderId: number;
  orderSn: string;
  productAttr: string;
  productBrand: string;
  productCount: number;
  productId: number;
  productName: string;
  productPic: string;
  productPrice: number;
  productRealPrice: number;
  proofPics: string;
  reason: string;
  receiveMan: string;
  receiveNote: string;
  receiveTime: string;
  returnAmount: number;
  returnName: string;
  returnPhone: string;
  status: number;
}
export const getReturnApplyList = (
  data: IReturnApplyListParmas
): Promise<IReturnApplyListRes> =>
  instance.get("returnApply/list", { params: data });

/* 
  /returnApply/{id} 
获取退货申请详情
  */

export const getReturnApply = (id: number): Promise<IReturnApplyListRes> =>
  instance.get(`returnApply/${id}`);

/* 
  /companyAddress/list  获取所有收货地址
  */

export interface ICompanyAddress {
  addressName?: string;
  city?: string;
  detailAddress?: string;
  id?: number;
  name?: string;
  phone?: string;
  province?: string;
  receiveStatus?: number;
  region?: string;
  sendStatus?: number;
}

export const getcompanyAddressList = (): Promise<ICompanyAddress> =>
  instance.get(`companyAddress/list`);

interface IReturnApplyupdate {
  companyAddressId: number;
  handleMan: string;
  handleNote: string;
  id: number;
  receiveMan: string;
  receiveNote: string;
  returnAmount: number;
  status: number;
}

/* 
  
/returnApply/update/status/{id}
修改退货申请状态
  */

export const returnApplyUpdate = (data: IReturnApplyupdate): Promise<any> =>
  instance.post(`returnApply/update/status/${data.id}`, data);

export interface Iorder {
  autoConfirmDay: 0;
  billContent: string;
  billHeader?: string;
  billReceiverEmail: string;
  billReceiverPhone: string;
  billType: 0;
  commentTime: string;
  confirmStatus: 0;
  couponAmount: 0;
  couponId: 0;
  createTime: string;
  deleteStatus: 0;
  deliveryCompany: string;
  deliverySn: string;
  deliveryTime: string;
  discountAmount: 0;
  freightAmount: 0;
  growth: 0;
  historyList: [
    {
      createTime: string;
      id: 0;
      note: string;
      operateMan: string;
      orderId: 0;
      orderStatus: 0;
    }
  ];
  id: 0;
  integration: 0;
  integrationAmount: 0;
  memberId: 0;
  memberUsername: string;
  modifyTime: string;
  note: string;
  orderItemList: [
    {
      couponAmount: 0;
      giftGrowth: 0;
      giftIntegration: 0;
      id: 0;
      integrationAmount: 0;
      orderId: 0;
      orderSn: string;
      productAttr: string;
      productBrand: string;
      productCategoryId: 0;
      productId: 0;
      productName: string;
      productPic: string;
      productPrice: 0;
      productQuantity: 0;
      productSkuCode: string;
      productSkuId: 0;
      productSn: string;
      promotionAmount: 0;
      promotionName: string;
      realAmount: 0;
    }
  ];
  orderSn: string;
  orderType: 0;
  payAmount: 0;
  payType: 0;
  paymentTime: string;
  promotionAmount: 0;
  promotionInfo: string;
  receiveTime: string;
  receiverCity: string;
  receiverDetailAddress: string;
  receiverName: string;
  receiverPhone: string;
  receiverPostCode: string;
  receiverProvince: string;
  receiverRegion: string;
  sourceType: 0;
  status: 0;
  totalAmount: 0;
  useIntegration: 0;
}
interface getOrderRes {
  message: string;
  code: number;
  data: Iorder[];
}
/*  
/order/{id}
获取订单详情：订单信息、商品信息、操作记录
*/
export const getOrder = (id: number): Promise<getOrderRes> =>
  instance.get(`order/${id}`);

/* 
  /order/update/note
  备注订单

 */
interface OrderUpdate {
  id: number;
  note: string;
  status: number;
}

export const OrderUpdate = (data: OrderUpdate): any =>
  instance.post(
    `order/update/note?id=${data.id}&note=${data.note}&status=${data.status}`
  );

// returnReason/list

export interface IreturnReasonList {
  createTime: string;
  id?: number | [];
  name?: string;
  sort: number;
  status: number;
}
interface IAdminListRes {
  list: IreturnReasonList[];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}
interface IAdminListParmas {
  keyword?: string | Ref<string>;
  pageNum?: number | Ref<number>;
  pageSize?: number | Ref<number>;
}

export const getReturnReasonList = (
  data: IAdminListParmas
): Promise<IAdminListRes> =>
  instance.get("returnReason/list", { params: data });

/* 
  /returnReason/update/{id}
修改退货原因
*/

export const returnReasonUpdate = (data: IreturnReasonList): any =>
  instance.post(`returnReason/update/${data.id}`, data);

/* 
  returnReason/update/status
  修改退货原因启用状态

  */

export interface returnReasonUpdateStatusRes {
  [x: string]: any;
  ids: number;
  status: number | boolean;
}

export const returnReasonUpdateStatus = (
  data: returnReasonUpdateStatusRes
): any =>
  instance.post(
    `returnReason/update/status?status=${data.status}&ids=${data.ids}`,
    data
  );

// returnReason/delete  批量删除退货原因

export const returnReasondelete = (ids: any): any =>
  instance.post(`returnReason/delete?ids=${ids}`);

// returnReason/create

export const returnReasonCreate = (data: IreturnReasonList): any =>
  instance.post(`returnReason/create`, data);
